﻿namespace LiteBlog.Common.Entities
{
    using System;
    using System.Collections.Generic;

    public class DraftPost : Post
    {
        public DraftPost()
        {
            this.Type = DraftType.New;
            this.DraftID = string.Empty;
            OldCategories = Categories;
            OldTags = Tags;
        }

        public DraftPost(Post post)
        {
            this.FileID = post.FileID;
            this.Type = DraftType.Published;
            OldCategories = Categories = post.Categories;
            OldTags = Tags = post.Tags;

            this.Title = post.Title;
            this.Author = post.Author;
            this.Time = post.Time;
            this.Meta = post.Meta;

            this.Comments = post.Comments;
            this.Documents = post.Documents;
            this.Contents = post.Contents;
        }

     
        public string DraftID { get; set; }
        public List<Category> OldCategories { get; set; }
        public IEnumerable<Tag> OldTags { get; set; }
        public DraftType Type { get; set; }
        
        public static string GetNewDraftID(string fileID, DateTime now)
        {
            return string.Format("{0}-Draft-{1}", fileID, now.ToString("MMddyyhhmmss"));
        }

        public static bool IsDraft(string fileID)
        {
            return fileID.Contains("-Draft-");
        }
    }
}